<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"  xmlns:sec="http://www.thymeleaf.org/extras/spring-security">

<div id="page-content">
    <div class="panel">

        <div class="panel-heading">
            <h3 class="panel-title">指标卡片</h3>
        </div>

        <div class="panel-body">

            <div class="row">
                <div class="col-sm-6 table-toolbar-left">
                    <button type="button" class="btn btn-primary btn-sm" id="btn-target-add" th:disabled="${!isCreator}">新建指标卡片</button>
                </div>
            </div>

            <div class="jqGrid_wrapper">
                <table id="target_table"></table>
                <div id="target_page"></div>
            </div>

        </div>

    </div>
</div>

<script th:inline="javascript">
    $(function(){
        init_grid_target();
    });

    function init_grid_target(){
        __init_jqgrid('target_table', 'target_page', '/target/list',
            ["指标名称","指标分类","指标重要等级","标签数","创建时间","最后更新时间","pathCount","操作","id"],
            [
                {name: 'name', index: 'name', width: 100, sortable: false, searchoptions: {sopt: ['cn']}},
                {name: 'targetClassDict.name', index: 'targetClassDict.name', width: 100, sortable: false, searchoptions: {sopt: ['cn']}},
                {name: 'targetLevelStr', index: 'targetLevelStr', width: 100, sortable: false, searchoptions: {sopt: ['cn']}},
                {name: 'labelCount', index: 'labelCount', width: 100, sortable: false, search : false, searchoptions: {sopt: ['cn']}},
                {name: 'finishTime', index: 'finishTime', width: 100, sortable: false, searchoptions: {sopt: ['cn']}},
                {name: 'lastUpdateTime', index: 'lastUpdateTime', width: 100, sortable: false, searchoptions: {sopt: ['cn']}},
                {name: 'pathCount', index: 'pathCount', width: 100, sortable: false, hidden: true},
                {name: 'act', index: 'act', width: 150, sortable: false, search: false, formatter: actFormat_target},
                {name: 'id', index: 'id', width: 100, key: true, hidden: true}
            ]
        );
    }

    function actFormat_target(cellvalue, options, rowObject){
        var id = rowObject.id;
        cellvalue = '<button class="btn btn-default btn-xs" onclick="fn_target_read(\'' + id + '\');">查看</button> ';
        cellvalue += '<button class="btn btn-primary btn-xs" onclick="fn_target_edit_label(\'' + id + '\');">标签设置</button> ';
        cellvalue += '<button class="btn btn-primary btn-xs" onclick="fn_target_edit_related(\'' + id + '\');">指标关联设置</button> ';
        return cellvalue;
    }

    //input
    $("#btn-target-add").on("click", function(){
        __layX_html_read("create", "指标卡片", "/target/input");
    });

    //read
    function fn_target_read(id){
        __layX_html_read(id, "指标卡片", "/target/read?keyId="+id);
    }

    //修改标签
    function fn_target_edit_label(id){
        __layX_html_read(id, "编辑指标标签", ctx+"target/input?editType=label&keyId="+id);
    }

    //指标关联设置
    function fn_target_edit_related(id){
        __layX_html_read(id, "指标关联设置", ctx+"target/input?editType=related&keyId="+id);
    }

</script>

</html>